package com.java.comprehensive.design.behavioral_model.Interpreter_pattern;

import lombok.AllArgsConstructor;
import lombok.ToString;

/**
 * 减法表达式类
 */
@AllArgsConstructor
public class Minus extends AbstractExpression {
    // -号 左边的表达式
    private AbstractExpression left;
    // -号 右边的表达式
    private AbstractExpression right;

    @Override
    public int interpret(Context context) {
        return left.interpret(context) - right.interpret(context);
    }

    @Override
    public String toString() {
        return "(" + left.toString() + "-" + right.toString() + ")";
    }
}
